/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmOrder.java
 *
 * Created on May 22, 2011, 7:51:13 AM
 */

package Ordermanagement;

import Account.SizeMonition;
import Connections.DataTools;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author BachDEV
 */
public class frmOrder extends javax.swing.JFrame {

    JTable tbOrder = null;
    JTable tbCus = null;
    public Vector vecValue = null;
    Vector vecCus = null;
    String[] arr = null;
    int n = 0, num = 0;
    int cusID;
    boolean flag = true;
    boolean flagCus = true, flagSelect = true;
    String cbSelect = "", cbSelectCus = "";
    Login.frmLogin login;
    int proID;
    double price;
    public static int x ;
    public static int y ;

    /** Creates new form frmOrder */
    public frmOrder(Login.frmLogin login) {
        try{
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }catch(InstantiationException ex){
            ex.printStackTrace();
        }catch(UnsupportedLookAndFeelException ex){
            ex.printStackTrace();
        }catch(ClassNotFoundException ex){
            ex.printStackTrace();
        }catch(IllegalAccessException ex){
            ex.printStackTrace();
        }
        try
        {
            Thread.sleep(1000);
            initComponents();
            this.login = login;
            Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();
            x = this.getWidth();
            y = this.getHeight();
            this.setLocation((ds.width - this.getWidth()) / 2, (ds.height - this.getHeight()) / 2);
            //motion();
            DataTools dt = new DataTools();
            showOrders(dt.getOrders());
            showCustormer(dt.getCustormer());
           cbSearchByActionPerformed(null);
           cbSearchOrderActionPerformed(null);
           Date now = new Date(System.currentTimeMillis());
           SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
           String today = sdf.format(now);
           txtDate.setText(today);
           txtDate.setEnabled(false);
           btnEditCus.setEnabled(false);
           btnAdd.setEnabled(false);
           txtProName.setEnabled(false);
           this.login.setVisible(false);
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage());
            return;
        }
    }
    public void motion() {
        this.setSize(0, 0);
        new Thread(new SizeMonition(this, x, y)).start();
    }
    /////////////////////////////////////////////////////////////////////
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabOrder = new javax.swing.JTabbedPane();
        panelOrder = new javax.swing.JPanel();
        scrOrder = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        txtPhone = new javax.swing.JTextField();
        cbPay = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtDate = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaAddress = new javax.swing.JTextArea();
        btnSelect = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        txtProName = new javax.swing.JTextField();
        btnSelectPro = new javax.swing.JButton();
        jLabel23 = new javax.swing.JLabel();
        txtQuantity = new javax.swing.JTextField();
        btnUpdate = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnDetail = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        cbSearchOrder = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        txtSeaOrdName = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtSeaOrdPhone = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        btnSearchOrd = new javax.swing.JButton();
        try
        {
            txfDate = new javax.swing.JFormattedTextField(new MaskFormatter("####/##/##"));
            jLabel1 = new javax.swing.JLabel();
            try
            {
                txfDateEnd = new javax.swing.JFormattedTextField(new MaskFormatter("####/##/##"));
                jLabel21 = new javax.swing.JLabel();
                panelCustomer = new javax.swing.JPanel();
                scrCustomer = new javax.swing.JScrollPane();
                btnAddCus = new javax.swing.JButton();
                btnEditCus = new javax.swing.JButton();
                btnExitCus = new javax.swing.JButton();
                jPanel2 = new javax.swing.JPanel();
                jLabel7 = new javax.swing.JLabel();
                jLabel8 = new javax.swing.JLabel();
                txtCusName = new javax.swing.JTextField();
                jScrollPane2 = new javax.swing.JScrollPane();
                txaCusAddress = new javax.swing.JTextArea();
                jLabel9 = new javax.swing.JLabel();
                txtCusPhone = new javax.swing.JTextField();
                jLabel10 = new javax.swing.JLabel();
                txtCusEmail = new javax.swing.JTextField();
                jLabel12 = new javax.swing.JLabel();
                txtDispatch = new javax.swing.JTextField();
                jLabel11 = new javax.swing.JLabel();
                cbCusStatus = new javax.swing.JComboBox();
                jPanel3 = new javax.swing.JPanel();
                jLabel13 = new javax.swing.JLabel();
                jLabel14 = new javax.swing.JLabel();
                txtSearchEmail = new javax.swing.JTextField();
                cbSearchBy = new javax.swing.JComboBox();
                jLabel15 = new javax.swing.JLabel();
                txtSearchPhone = new javax.swing.JTextField();
                jLabel16 = new javax.swing.JLabel();
                txtSearchDispatch = new javax.swing.JTextField();
                btnSearch = new javax.swing.JButton();
                jMenuBar1 = new javax.swing.JMenuBar();
                mnuTask = new javax.swing.JMenu();
                mnuOrder = new javax.swing.JMenuItem();
                mnuCus = new javax.swing.JMenuItem();
                mnuLogout = new javax.swing.JMenuItem();
                mnuExit = new javax.swing.JMenuItem();
                jMenu2 = new javax.swing.JMenu();
                mnuItemHelp = new javax.swing.JMenuItem();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

                panelOrder.setPreferredSize(new java.awt.Dimension(561, 548));

                jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Add or Edit new order", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 16))); // NOI18N

                cbPay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "UnCheck", "Checked" }));

                jLabel2.setText("Date:");

                jLabel6.setText("Pay:");

                jLabel3.setText("Address:");

                jLabel4.setText("Phone:");

                jLabel5.setText("Name:");

                jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

                txaAddress.setColumns(20);
                txaAddress.setRows(5);
                jScrollPane1.setViewportView(txaAddress);

                btnSelect.setText("Select Custormer");
                btnSelect.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnSelectActionPerformed(evt);
                    }
                });

                jLabel22.setText("Product name:");

                btnSelectPro.setText("Select");
                btnSelectPro.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnSelectProActionPerformed(evt);
                    }
                });

                jLabel23.setText("Quantity:");

                javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
                jPanel1.setLayout(jPanel1Layout);
                jPanel1Layout.setHorizontalGroup(
                    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel23))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                                    .addComponent(txtDate, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                                    .addComponent(txtPhone, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                                    .addComponent(cbPay, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtProName, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnSelectPro, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                                    .addComponent(txtQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(90, 90, 90)
                                .addComponent(btnSelect)))
                        .addContainerGap())
                );
                jPanel1Layout.setVerticalGroup(
                    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22)
                            .addComponent(txtProName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnSelectPro))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(txtQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbPay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSelect))
                );

                btnUpdate.setText("Edit");
                btnUpdate.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnUpdateActionPerformed(evt);
                    }
                });

                btnExit.setText("Exit");
                btnExit.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnExitActionPerformed(evt);
                    }
                });

                btnAdd.setText("Add");
                btnAdd.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnAddActionPerformed(evt);
                    }
                });

                btnDetail.setText("Detail");
                btnDetail.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnDetailActionPerformed(evt);
                    }
                });

                jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search Order", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 16))); // NOI18N

                jLabel17.setText("Search by:");

                cbSearchOrder.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Name", "Phone", "Date" }));
                cbSearchOrder.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        cbSearchOrderActionPerformed(evt);
                    }
                });

                jLabel18.setText("Name:");

                jLabel19.setText("Phone:");

                jLabel20.setText("Date start:");

                btnSearchOrd.setText("Search");
                btnSearchOrd.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        btnSearchOrdActionPerformed(evt);
                    }
                });

            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(this, ex.getMessage());
            }

            jLabel1.setText("Date end:");

        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }

        jLabel21.setText("(yyyy/MM/dd)");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel20)
                            .addComponent(jLabel19)
                            .addComponent(jLabel18)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txfDateEnd)
                            .addComponent(txfDate)
                            .addComponent(cbSearchOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSeaOrdPhone)
                            .addComponent(txtSeaOrdName, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(129, 129, 129)
                        .addComponent(jLabel21))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(btnSearchOrd, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(cbSearchOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSeaOrdName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSeaOrdPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(txfDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txfDateEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnSearchOrd)
                .addContainerGap())
        );

        javax.swing.GroupLayout panelOrderLayout = new javax.swing.GroupLayout(panelOrder);
        panelOrder.setLayout(panelOrderLayout);
        panelOrderLayout.setHorizontalGroup(
            panelOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelOrderLayout.createSequentialGroup()
                .addGroup(panelOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelOrderLayout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 135, Short.MAX_VALUE)
                        .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelOrderLayout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(panelOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelOrderLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelOrderLayout.createSequentialGroup()
                        .addGap(87, 87, 87)
                        .addComponent(btnDetail, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
            .addComponent(scrOrder, javax.swing.GroupLayout.DEFAULT_SIZE, 799, Short.MAX_VALUE)
        );
        panelOrderLayout.setVerticalGroup(
            panelOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelOrderLayout.createSequentialGroup()
                .addComponent(scrOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(panelOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnUpdate)
                    .addComponent(btnDetail)
                    .addComponent(btnExit))
                .addContainerGap())
        );

        tabOrder.addTab("Order List", panelOrder);

        panelCustomer.setPreferredSize(new java.awt.Dimension(561, 558));

        btnAddCus.setText("Add");
        btnAddCus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddCusActionPerformed(evt);
            }
        });

        btnEditCus.setText("Edit");
        btnEditCus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditCusActionPerformed(evt);
            }
        });

        btnExitCus.setText("Exit");
        btnExitCus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitCusActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Add or Edit Custormer", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 16))); // NOI18N

        jLabel7.setText("Name:");

        jLabel8.setText("Address:");

        txaCusAddress.setColumns(20);
        txaCusAddress.setRows(5);
        jScrollPane2.setViewportView(txaCusAddress);

        jLabel9.setText("Phone:");

        jLabel10.setText("Email:");

        jLabel12.setText("Dispatch:");

        jLabel11.setText("Status:");

        cbCusStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Show", "Hide" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGap(14, 14, 14)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(txtCusName, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(txtCusPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(txtCusEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(txtDispatch, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(cbCusStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtCusName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(8, 8, 8)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtCusPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtCusEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtDispatch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(cbCusStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search Custormer", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 16))); // NOI18N

        jLabel13.setText("Search by:");

        jLabel14.setText("Email:");

        cbSearchBy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Email", "Phone", "Dispatch" }));
        cbSearchBy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbSearchByActionPerformed(evt);
            }
        });

        jLabel15.setText("Phone:");

        jLabel16.setText("Dispatch:");

        btnSearch.setText("Search");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel16)
                            .addComponent(jLabel15)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtSearchEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                            .addComponent(cbSearchBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSearchPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                            .addComponent(txtSearchDispatch, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(cbSearchBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtSearchEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtSearchPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txtSearchDispatch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(btnSearch)
                .addContainerGap())
        );

        javax.swing.GroupLayout panelCustomerLayout = new javax.swing.GroupLayout(panelCustomer);
        panelCustomer.setLayout(panelCustomerLayout);
        panelCustomerLayout.setHorizontalGroup(
            panelCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelCustomerLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(74, 74, 74)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41))
            .addComponent(scrCustomer, javax.swing.GroupLayout.DEFAULT_SIZE, 807, Short.MAX_VALUE)
            .addGroup(panelCustomerLayout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(btnAddCus, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 171, Short.MAX_VALUE)
                .addComponent(btnEditCus, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(161, 161, 161)
                .addComponent(btnExitCus, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(131, 131, 131))
        );
        panelCustomerLayout.setVerticalGroup(
            panelCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCustomerLayout.createSequentialGroup()
                .addComponent(scrCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addGroup(panelCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panelCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddCus)
                    .addComponent(btnEditCus)
                    .addComponent(btnExitCus))
                .addContainerGap(53, Short.MAX_VALUE))
        );

        tabOrder.addTab("Customer List", panelCustomer);

        mnuTask.setText("Task");
        mnuTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuTaskActionPerformed(evt);
            }
        });

        mnuOrder.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        mnuOrder.setText("Order List");
        mnuOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuOrderActionPerformed(evt);
            }
        });
        mnuTask.add(mnuOrder);

        mnuCus.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        mnuCus.setText("Custormer List");
        mnuCus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCusActionPerformed(evt);
            }
        });
        mnuTask.add(mnuCus);

        mnuLogout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        mnuLogout.setText("Logout");
        mnuLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuLogoutActionPerformed(evt);
            }
        });
        mnuTask.add(mnuLogout);

        mnuExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        mnuExit.setText("Exit");
        mnuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuExitActionPerformed(evt);
            }
        });
        mnuTask.add(mnuExit);

        jMenuBar1.add(mnuTask);

        jMenu2.setText("Help");

        mnuItemHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        mnuItemHelp.setText("Help");
        mnuItemHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemHelpActionPerformed(evt);
            }
        });
        jMenu2.add(mnuItemHelp);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 804, Short.MAX_VALUE)
            .addComponent(tabOrder, javax.swing.GroupLayout.DEFAULT_SIZE, 804, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 628, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 628, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuOrderActionPerformed
        tabOrder.setSelectedIndex(0);
}//GEN-LAST:event_mnuOrderActionPerformed

    private void mnuCusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCusActionPerformed
        tabOrder.setSelectedIndex(1);
}//GEN-LAST:event_mnuCusActionPerformed

    private void mnuLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuLogoutActionPerformed
        int option = JOptionPane.showConfirmDialog(this, "Do you want to log out?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (option == JOptionPane.OK_OPTION) {
            dispose();
            login.setVisible(true);
            login.pwdPassword.setText("");
            login.txtUserName.setText("");
        }
}//GEN-LAST:event_mnuLogoutActionPerformed

    private void mnuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuExitActionPerformed
        int n = JOptionPane.showConfirmDialog(this, "Are you exit?", "Config", 0, 3);
        if(n == 0)
            System.exit(1);
}//GEN-LAST:event_mnuExitActionPerformed

    private void mnuTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuTaskActionPerformed

}//GEN-LAST:event_mnuTaskActionPerformed

    private void mnuItemHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemHelpActionPerformed
        // TODO add your handling code here:
        try {
            Runtime.getRuntime().exec("hh.exe " + "eProject.chm");
        } catch (IOException ex) {
        }
}//GEN-LAST:event_mnuItemHelpActionPerformed

    private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectActionPerformed
        btnAdd.setEnabled(true);
        flagSelect = false;
        frmSearchCus cus = new frmSearchCus(this);
        cus.setVisible(true);
        cus.setAlwaysOnTop(true);
}//GEN-LAST:event_btnSelectActionPerformed

    private void btnSelectProActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectProActionPerformed
        try {
            frmProduct pro = new frmProduct(this);
            pro.setVisible(true);
            pro.setAlwaysOnTop(true);
        } catch(Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnSelectProActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        num++;
        btnAdd.setEnabled(true);
        flag = false;
        editOrder();
}//GEN-LAST:event_btnUpdateActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        int n = JOptionPane.showConfirmDialog(this, "Are you exit?", "Config", 0, 3);
        if(n == 0)
            System.exit(1);
}//GEN-LAST:event_btnExitActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        updateOrders();
        resetOrder();
}//GEN-LAST:event_btnAddActionPerformed

    private void btnDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetailActionPerformed
        // TODO add your handling code here:
        frmDetails details = new frmDetails(this);
        details.setVisible(true);
        details.setAlwaysOnTop(true);
        this.setEnabled(false);
}//GEN-LAST:event_btnDetailActionPerformed

    private void cbSearchOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSearchOrderActionPerformed
        try {
            DataTools dt = new DataTools();
            String select = cbSearchOrder.getSelectedItem().toString();
            if("Name".equalsIgnoreCase(select)) {
                txtSeaOrdName.setText("");
                txfDate.setText("");
                txfDateEnd.setText("");
                txtSeaOrdPhone.setText("");
                txtSeaOrdName.setEnabled(true);
                txfDate.setEnabled(false);
                txfDateEnd.setEnabled(false);
                txtSeaOrdPhone.setEnabled(false);
                showOrders(dt.getOrders());
                cbSelect = "NameCus";
            }
            if("Phone".equalsIgnoreCase(select)) {
                txtSeaOrdName.setText("");
                txfDate.setText("");
                txfDateEnd.setText("");
                txtSeaOrdPhone.setText("");
                txtSeaOrdName.setEnabled(false);
                txfDate.setEnabled(false);
                txfDateEnd.setEnabled(false);
                txtSeaOrdPhone.setEnabled(true);
                showOrders(dt.getOrders());
                cbSelect = "Phone";
            }
            if("Date".equalsIgnoreCase(select)) {
                txtSeaOrdName.setText("");
                txfDate.setText("");
                txfDateEnd.setText("");
                txtSeaOrdPhone.setText("");
                txtSeaOrdName.setEnabled(false);
                txfDate.setEnabled(true);
                txfDateEnd.setEnabled(true);
                txtSeaOrdPhone.setEnabled(false);
                showOrders(dt.getOrders());
                cbSelect = "Date";
            }
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
            return;
        }
}//GEN-LAST:event_cbSearchOrderActionPerformed

    private void btnSearchOrdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchOrdActionPerformed
        try {
            DataTools dt = new DataTools();
            Vector vec = new Vector();
            if("NameCus".equalsIgnoreCase(cbSelect)) {
                if("".equalsIgnoreCase(txtSeaOrdName.getText())) {
                    JOptionPane.showMessageDialog(this, "Name is not null");
                    return;
                }
                String name = txtSeaOrdName.getText();
                System.out.println("Name:" + name);
                vec = dt.searchOrder(name, 1);
                if(vec.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "Name is not found");
                    return;
                } else {
                    showOrders(vec);
                }
            }
            if("Phone".equalsIgnoreCase(cbSelect)) {
                if("".equalsIgnoreCase(txtSeaOrdPhone.getText())) {
                    JOptionPane.showMessageDialog(this, "Phone is not null");
                    return;
                }
                vec = dt.searchOrder(txtSeaOrdPhone.getText(), 2);
                if(vec.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "Phone number is not found");
                    return;
                } else {
                    showOrders(vec);
                }
            }
            if("Date".equalsIgnoreCase(cbSelect)) {
                System.out.println("Date End: " + txfDateEnd.getName());
                if(txfDateEnd.getText() == null) {
                    vec = dt.searchOrder(txfDate.getText(), 3);
                } else {
                    vec = dt.searchDateSE(txfDate.getText(), txfDateEnd.getText());
                }
                if(vec.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "Date is not found");
                    return;
                } else {
                    showOrders(vec);
                }
            }
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnSearchOrdActionPerformed

    private void btnAddCusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddCusActionPerformed
        try {
            DataTools dt = new DataTools();
            Vector vec = new Vector();
            if("".equalsIgnoreCase(txtCusName.getText())) {
                JOptionPane.showMessageDialog(this, "Name is not null");
                return;
            }
            String name = txtCusName.getText();
            for(int i = 0; i< name.length(); i++) {
                if(name.charAt(i) >= 48 && name.charAt(i) <= 57) {
                    JOptionPane.showMessageDialog(this, "Name is not contain number");
                    return;
                }
            }

            if("".equalsIgnoreCase(txtCusPhone.getText())) {
                JOptionPane.showMessageDialog(this, "Phone is not null");
                return;
            }
            try {
                double dphone = Double.parseDouble(txtCusPhone.getText());
            } catch(Exception ex) {
                JOptionPane.showMessageDialog(this, "Phone only can is number");
                return;
            }

            if("".equalsIgnoreCase(txtDispatch.getText())) {
                JOptionPane.showMessageDialog(this, "Dispatch is not null");
                return;
            }
            vec.add(txtCusName.getText());
            vec.add(txaCusAddress.getText());
            vec.add(txtCusPhone.getText());
            vec.add(txtCusEmail.getText());
            if(cbCusStatus.getSelectedIndex() == 0) {
                vec.add("True");
            } else {
                vec.add("False");
            }
            vec.add(txtDispatch.getText());
            if(!flagCus) {
                vec.add(vecCus.get(0));
                int n = dt.updateCus(vec);
                if(n != 0) {
                    JOptionPane.showMessageDialog(this, "You are update succeessful");
                    showCustormer(dt.getCustormer());
                    return;
                } else {
                    JOptionPane.showMessageDialog(this, "You are update unsuccessfull");
                    return;
                }
            } else {
                int n = dt.addCus(vec);
                if(n != 0) {
                    JOptionPane.showMessageDialog(this, "You are add successful");
                    showCustormer(dt.getCustormer());
                    resetCus();
                } else {
                    JOptionPane.showMessageDialog(this, "You are add unsuccessfull");
                }
            }
            flagCus = true;
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnAddCusActionPerformed

    private void btnEditCusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditCusActionPerformed
        txtCusName.setText(vecCus.get(1).toString());
        txaCusAddress.setText(vecCus.get(2).toString());
        txtCusPhone.setText(vecCus.get(3).toString());
        txtCusEmail.setText(vecCus.get(4).toString());
        cbPay.setSelectedItem(vecCus.get(5));
        txtDispatch.setText(vecCus.get(6).toString());
        flagCus = false;
}//GEN-LAST:event_btnEditCusActionPerformed

    private void btnExitCusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitCusActionPerformed
        int n = JOptionPane.showConfirmDialog(this, "Are you exit?", "Config", 0, 3);
        if(n == 0)
            System.exit(1);
}//GEN-LAST:event_btnExitCusActionPerformed

    private void cbSearchByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSearchByActionPerformed
        try {
            String select = (String)cbSearchBy.getSelectedItem();
            DataTools dt = new DataTools();
            if("Phone".equalsIgnoreCase(select)) {
                txtSearchPhone.setText("");
                txtSearchEmail.setText("");
                txtSearchDispatch.setText("");
                txtSearchPhone.setEnabled(true);
                txtSearchEmail.setEnabled(false);
                txtSearchDispatch.setEnabled(false);
                showCustormer(dt.getCustormer());
                cbSelectCus = "PhoneCus";
            }
            if("Email".equalsIgnoreCase(select)) {
                txtSearchPhone.setText("");
                txtSearchEmail.setText("");
                txtSearchDispatch.setText("");
                txtSearchPhone.setEnabled(false);
                txtSearchEmail.setEnabled(true);
                txtSearchDispatch.setEnabled(false);
                showCustormer(dt.getCustormer());
                cbSelectCus = "Email";
            }
            if("Dispatch".equalsIgnoreCase(select)) {
                txtSearchPhone.setText("");
                txtSearchEmail.setText("");
                txtSearchDispatch.setText("");
                txtSearchPhone.setEnabled(false);
                txtSearchEmail.setEnabled(false);
                txtSearchDispatch.setEnabled(true);
                showCustormer(dt.getCustormer());
                cbSelectCus = "Dispatch";
            }
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
            return;
        }
}//GEN-LAST:event_cbSearchByActionPerformed

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        try {
            DataTools dt = new DataTools();
            Vector vec = new Vector();
            if("Email".equalsIgnoreCase(cbSelectCus)) {
                if("".equalsIgnoreCase(txtSearchEmail.getText())) {
                    JOptionPane.showMessageDialog(this, "Email is not null");
                    return;
                }
                String email = txtSearchEmail.getText();
                System.out.println("Name:" + email);
                vec = dt.searchCus(email, 2);
                if(vec.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "Email is not found");
                    return;
                } else {
                    showCustormer(vec);
                }
            }
            if("PhoneCus".equalsIgnoreCase(cbSelectCus)) {
                if("".equalsIgnoreCase(txtSearchPhone.getText())) {
                    JOptionPane.showMessageDialog(this, "Phone is not null");
                    return;
                }
                vec = dt.searchCus(txtSearchPhone.getText(), 1);
                if(vec.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "Phone is not found");
                    return;
                } else {
                    showCustormer(vec);
                }
            }
            if("Dispatch".equalsIgnoreCase(cbSelectCus)) {
                System.out.println("Dispatch: "+txtSearchDispatch.getText());
                vec = dt.searchCus(txtSearchDispatch.getText(), 3);
                if(vec.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "Dispatch is not found");
                    return;
                } else {
                    showCustormer(vec);
                }
            }
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnSearchActionPerformed

//////////////////////////////////////////////////////////////////////////////////
    public void showOrders(Vector vec)
    {
         try
        {
             btnUpdate.setEnabled(false);
             btnDetail.setEnabled(false);
            Vector ve = new Vector();
            ve.add("ID");
            ve.add("Cust ID");
            ve.add("Order Date");
            ve.add("Address");
            ve.add("Phone");
            ve.add("Name");
            ve.add("Pay Status");
            ve.add("Dispatch Status");
            tbOrder = new JTable(vec, ve);
            tbOrder.addKeyListener(new KeyListener() {

                public void keyTyped(KeyEvent e) {

                }

                public void keyPressed(KeyEvent e) {

                }

                public void keyReleased(KeyEvent e) {
                   if(tbOrder.getSelectedRow() != -1)
                   {
                        btnUpdate.setEnabled(true);
                        btnDetail.setEnabled(true);
                        num = 0;

                        int selectRow = tbOrder.getSelectedRow();
                        int cols = tbOrder.getColumnCount();
                        n = cols;
                        arr = new String[cols];
                        for(int i = 0; i<cols; i++)
                        {
                            Object value = tbOrder.getValueAt(selectRow, i);
                            arr[i] = value.toString();
                        }
                   }
                }
            });
            scrOrder.setViewportView(tbOrder);
            tbOrder.getColumnModel().getColumn(0).setMinWidth(0);
            tbOrder.getColumnModel().getColumn(0).setMaxWidth(0);
            tbOrder.getColumnModel().getColumn(1).setMinWidth(0);
            tbOrder.getColumnModel().getColumn(1).setMaxWidth(0);
            btnAdd.setEnabled(false);
            btnUpdate.setEnabled(false);
            clicktbOrder();
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }
    public void editOrder()
    {
        frmOrder fo = new frmOrder(login);
        if(fo.num == 0)
        {
            String arr2[] = arr[2].split(" ");
            if(arr2.length > 1)
            {
                String arr3[] = arr2[0].split("-");
                arr[2] = arr3[0]+"/" + arr3[1]+ "/" + arr3[2];
            }
        }
        txtDate.setText(arr[2]);
        txtDate.setEnabled(false);
        txaAddress.setText(arr[3]);
        txtPhone.setText(arr[4]);
        txtName.setText(arr[5]);
        System.out.println("arr address: "+arr[3].length());
        System.out.println("arr phone: "+arr[4].length());
        if("Uncheck".equalsIgnoreCase(arr[6]))
        {
            cbPay.setSelectedItem("Uncheck");
        }
        else
        {
            cbPay.setSelectedItem("Checked");
        }
    }

    public void clicktbOrder()
    {
         tbOrder.addMouseListener(new MouseListener() {

                public void mouseClicked(MouseEvent e) {
                    btnUpdate.setEnabled(true);
                    btnDetail.setEnabled(true);
                    num = 0;
                    int selectRow = tbOrder.getSelectedRow();
                    int cols = tbOrder.getColumnCount();
                    n = cols;
                    arr = new String[cols];
                    for(int i = 0; i<cols; i++)
                    {
                        Object value = tbOrder.getValueAt(selectRow, i);
                        arr[i] = value.toString();
                    }
                }

                public void mousePressed(MouseEvent e) {
                    System.out.println("Pressed");
                }

                public void mouseReleased(MouseEvent e) {
                    System.out.println("Released");
                }

                public void mouseEntered(MouseEvent e) {
                    System.out.println("Entered");
                }

                public void mouseExited(MouseEvent e) {

                }
            });
    }

    public void clicktbCustormer()
    {
        tbCus.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent e) {
                btnEditCus.setEnabled(true);
                vecCus = new Vector();
                int selectRow = tbCus.getSelectedRow();
                for(int i = 0; i< 7; i++)
                {
                    vecCus.add(tbCus.getValueAt(selectRow, i));
                }
                System.out.println("vecCus: "+vecCus.size());
            }

            public void mousePressed(MouseEvent e) {

            }

            public void mouseReleased(MouseEvent e) {

            }

            public void mouseEntered(MouseEvent e) {

            }

            public void mouseExited(MouseEvent e) {

            }
        });
    }
    public void showCustormer(Vector ve)
    {
        try
        {
            Vector vec = new Vector();
            Connections.DataTools dt = new Connections.DataTools();
            vec.add("ID");
            vec.add("Name");
            vec.add("Address");
            vec.add("Phone");
            vec.add("Email");
            vec.add("Status");
            vec.add("Dispatch No");
            tbCus = new JTable(ve, vec);
            tbCus.addKeyListener(new KeyListener() {

                public void keyTyped(KeyEvent e) {

                }

                public void keyPressed(KeyEvent e) {

                }

                public void keyReleased(KeyEvent e) {
                   if(tbCus.getSelectedRow() != -1)
                   {
                        btnEditCus.setEnabled(true);
                        num = 0;
                        int selectRow = tbCus.getSelectedRow();
                        int cols = tbCus.getColumnCount();
                        n = cols;
                        arr = new String[cols];
                        for(int i = 0; i<cols; i++)
                        {
                            Object value = tbCus.getValueAt(selectRow, i);
                            arr[i] = value.toString();
                        }
                   }
                }
            });
            scrCustomer.setViewportView(tbCus);
            tbCus.getColumnModel().getColumn(0).setMinWidth(0);
            tbCus.getColumnModel().getColumn(0).setMaxWidth(0);
            btnEditCus.setEnabled(false);
            clicktbCustormer();
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    public void resetOrder()
    {
        txtName.setText("");
        txaAddress.setText("");
        txtPhone.setText("");
        cbPay.setSelectedIndex(0);
    }

    public void resetCus()
    {
        txtCusEmail.setText("");
        txtCusName.setText("");
        txtCusPhone.setText("");
        txtDispatch.setText("");
        txaAddress.setText("");
        txtProName.setText("");
        txtQuantity.setText("");
        cbCusStatus.setSelectedIndex(0);
    }
    /////////////////////////////////////////////////////////////////////////
    public void updateOrders()
    {
         try
        {
            Vector vec = new Vector();
            String name = txtName.getText();
            if("".equalsIgnoreCase(name))
            {
                JOptionPane.showMessageDialog(this, "Name can not empty");
                return;
            }
            for(int i = 0; i<name.length(); i++)
            {
                if(name.charAt(i) >= 48 && name.charAt(i)<= 57)
                {
                    JOptionPane.showMessageDialog(this, "Name is can not contain number");
                    return;
                }
            }

            if("".equalsIgnoreCase(txaAddress.getText()))
            {
                JOptionPane.showMessageDialog(this, "Address is can not null");
                return;
            }

            if("".equalsIgnoreCase(txtPhone.getText()))
            {
                JOptionPane.showMessageDialog(this, "Phone is can not null");
                return;
            }
            String sdt = txtPhone.getText();
            double phone = 0;
            try
            {
                phone = Double.parseDouble(sdt);
            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(this, "Phone only can is number");
                return;
            }
            if(sdt.length() > 15)
            {
                JOptionPane.showMessageDialog(this, "length of phone number must be less than 15");
                return;
            }
            if("".equalsIgnoreCase(txtProName.getText()))
            {
                JOptionPane.showMessageDialog(this, "Product name is not null");
                return;
            }
            if("".equalsIgnoreCase(txtQuantity.getText()))
            {
                JOptionPane.showMessageDialog(this, "Quantity is not null");
                return;
            }
            int quantity;
            try
            {
                quantity = Integer.parseInt(txtQuantity.getText());
            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(this, "Quantity only can is number");
                return;
            }
            String address = txaAddress.getText();
            vec.add(txtDate.getText());
            vec.add(txtName.getText());
            vec.add(address);
            vec.add(txtPhone.getText());
            if(cbPay.getSelectedIndex() == 1)
            {
                vec.add("True");
            }
            else
            {
                vec.add("false");
            }
            vec.add(proID);
            vec.add(txtQuantity.getText());
            DataTools dt = new DataTools();
            if(!flag)
            {
                vec.add(arr[0]);
                vec.add(arr[1]);
                 dt.updateOrder(vec);
                 dt.updateOrderDetails(vec);
                 JOptionPane.showMessageDialog(this, "You are edit successful");
                 showOrders(dt.getOrders());
            }
            else
            {
                vec.add(cusID);
                dt.addOrder(vec);
                dt.addOrderDetails(vec);
                JOptionPane.showMessageDialog(this, "You are add successfull");
                showOrders(dt.getOrders());
            }
            flag = true;
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }
    ///////////////////////////////////////////////////////////////////////////
    /**
    * @param args the command line arguments
    */


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnAddCus;
    private javax.swing.JButton btnDetail;
    private javax.swing.JButton btnEditCus;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnExitCus;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSearchOrd;
    private javax.swing.JButton btnSelect;
    private javax.swing.JButton btnSelectPro;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JComboBox cbCusStatus;
    private javax.swing.JComboBox cbPay;
    private javax.swing.JComboBox cbSearchBy;
    private javax.swing.JComboBox cbSearchOrder;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JMenuItem mnuCus;
    private javax.swing.JMenuItem mnuExit;
    private javax.swing.JMenuItem mnuItemHelp;
    private javax.swing.JMenuItem mnuLogout;
    private javax.swing.JMenuItem mnuOrder;
    private javax.swing.JMenu mnuTask;
    private javax.swing.JPanel panelCustomer;
    private javax.swing.JPanel panelOrder;
    private javax.swing.JScrollPane scrCustomer;
    private javax.swing.JScrollPane scrOrder;
    private javax.swing.JTabbedPane tabOrder;
    public javax.swing.JTextArea txaAddress;
    private javax.swing.JTextArea txaCusAddress;
    private javax.swing.JFormattedTextField txfDate;
    private javax.swing.JFormattedTextField txfDateEnd;
    private javax.swing.JTextField txtCusEmail;
    private javax.swing.JTextField txtCusName;
    private javax.swing.JTextField txtCusPhone;
    private javax.swing.JTextField txtDate;
    private javax.swing.JTextField txtDispatch;
    public javax.swing.JTextField txtName;
    public javax.swing.JTextField txtPhone;
    public javax.swing.JTextField txtProName;
    private javax.swing.JTextField txtQuantity;
    private javax.swing.JTextField txtSeaOrdName;
    private javax.swing.JTextField txtSeaOrdPhone;
    private javax.swing.JTextField txtSearchDispatch;
    private javax.swing.JTextField txtSearchEmail;
    private javax.swing.JTextField txtSearchPhone;
    // End of variables declaration//GEN-END:variables

}
